"use strict";
const common_vendor = require("../../common/vendor.js");
const common_share = require("../../common/share.js");
const common_request = require("../../common/request.js");
let allDatas = [];
const _sfc_main = {
  onShareAppMessage() {
    return {
      title: "软水查询",
      imageUrl: ""
      // path: ""
    };
  },
  data() {
    return {
      currentActionIndex: -1,
      currentPeopleCode: null,
      currentHardCode: null,
      currentProduct: null,
      formItems: [
        { key: "currentPeopleCode", selectLabel: "", value: -1, placeholder: "请选择人口数量", label: "人口数量：", options: [] },
        { key: "currentHardCode", selectLabel: "", value: -1, placeholder: "请选择水质硬度", label: "水质硬度：", options: [] },
        { key: "currentProduct", selectLabel: "", value: -1, placeholder: "请选择产品系列", label: "产品系列：", options: [] }
      ],
      peopleList: [],
      hardnessList: [],
      productList: []
    };
  },
  onReady(options) {
    console.log("ready");
    this.querySoftWater();
  },
  methods: {
    querySoftWater() {
      common_request.service({
        url: "/water/softener"
      }).then((res) => {
        console.log(res);
        if (!res)
          return;
        allDatas = res;
        const peopleList = [];
        const hardnessList = [];
        const productList = [];
        peopleList.keys = {};
        hardnessList.keys = {};
        productList.keys = {};
        res.forEach((item) => {
          const { hardness_calc, hardness_range, population, range_value, product_model, product_series } = item;
          if (!hardnessList.keys[hardness_calc]) {
            hardnessList.push({ value: hardness_calc, label: hardness_range });
          }
          hardnessList.keys[hardness_calc] = hardness_range;
          if (!peopleList.keys[population]) {
            peopleList.push({ value: population, label: range_value });
          }
          peopleList.keys[population] = range_value;
          if (!productList.keys[product_series]) {
            productList.push({ value: product_series, label: product_series });
          }
          productList.keys[product_series] = product_series;
        });
        console.log(peopleList);
        console.log(hardnessList);
        console.log(productList);
        this.peopleList = peopleList;
        this.hardnessList = hardnessList;
        this.productList = productList;
        this.$set(this.formItems[0], "options", peopleList);
        this.$set(this.formItems[1], "options", hardnessList);
        this.$set(this.formItems[2], "options", productList);
      });
    },
    goToSolution() {
      const { currentPeopleCode, currentHardCode, currentProduct } = this;
      console.log(currentPeopleCode);
      console.log(currentHardCode);
      console.log(currentProduct);
      if (!currentPeopleCode || !currentHardCode || !currentProduct) {
        return common_vendor.index.showToast({
          title: "不能为空",
          icon: "none"
        });
      }
      const result = allDatas.filter((e) => {
        return e.population === currentPeopleCode && e.hardness_calc === currentHardCode && e.product_series === currentProduct;
      });
      console.log("匹配结果： ", result);
      common_share.setMatchResultList(result);
      common_vendor.index.navigateTo({
        url: "/pages/solution/solution"
      });
    },
    showAction(item, index) {
      this.currentActionIndex = index;
      const { options, key } = item;
      common_vendor.index.showActionSheet({
        itemList: options.map((e) => e.label),
        success: (res) => {
          console.log("选中了第" + (res.tapIndex + 1) + "个按钮");
          item.selectLabel = options[res.tapIndex].label;
          item.value = options[res.tapIndex].value;
          console.log(item.label);
          console.log(item.value);
          this[key] = item.value;
        },
        fail: function(res) {
          console.log(res.errMsg);
        },
        complete: () => {
          this.currentActionIndex = null;
        }
      });
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.f($data.formItems, (item, index, i0) => {
      return {
        a: common_vendor.t(item.label),
        b: common_vendor.t(item.selectLabel || item.placeholder),
        c: item.selectLabel ? 1 : "",
        d: $data.currentActionIndex === index ? 1 : "",
        e: common_vendor.o(($event) => $options.showAction(item, index), index),
        f: index
      };
    }),
    b: common_vendor.o((...args) => $options.goToSolution && $options.goToSolution(...args))
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "C:/Users/karo/Desktop/finale/3.0/clean-water/clean-water/pages/softwater/softwater.vue"]]);
_sfc_main.__runtimeHooks = 2;
wx.createPage(MiniProgramPage);
